﻿using System.Windows.Forms;
using CreateNetMessage;

namespace NetMessageTools
{
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        private readonly MessageManager msgManager = new MessageManager();

        private void FrmMain_Load(object sender, System.EventArgs e)
        {
            //ucMessage1.BindObjcet(new NetMessage.Message());
            msgManager.Load();
            messageBindingSource.DataSource = msgManager.Messages;
        }

        private void btnAddMsg_Click(object sender, System.EventArgs e)
        {
            messageBindingSource.Add(new NetMessage.Message()
                                        {
                                            Name = "NewMessage"
                                        });
        }

        private void ListBox1SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                ucMessage1.BindObjcet(listBox1.SelectedItem as NetMessage.Message);
            }
        }

        private void MenuLoadClick(object sender, System.EventArgs e)
        {
            msgManager.Load();
            messageBindingSource.DataSource = msgManager.Messages;
        }

        private void MenuSaveClick(object sender, System.EventArgs e)
        {
            msgManager.Save();
        }

        private void MenuQuitClick(object sender, System.EventArgs e)
        {
            Close();
        }

        private void btnDelMsg_Click(object sender, System.EventArgs e)
        {
            if (listBox1.SelectedItem != null)
            {
                messageBindingSource.Remove(listBox1.SelectedItem);
            }
        }

        private void MenuCodeFolderClick(object sender, System.EventArgs e)
        {
            new FrmSetting().ShowDialog();
        }
    }
}
